package com.aphrodite.ui.canvas;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

import com.aphrodite.util.BitmapFont;

public final class MacScreenMenu {
	private String caption;

	private int captionHeight;
	private int captionWidth;
	private int captionXPos;
	private int captionYPos;
	private String categoryId;
	private boolean hasSubmenu;
	private int iconXPos;
	private int iconYPos;
	private boolean isReport;
	private String menuId;
	private Image menuImage;
	private MacScreenMenu[] submenu;

	private int subMenuWidth;

	public MacScreenMenu(String caption) {
		// this.menuImage = menuImage;
		this.caption = caption;
	}

	void drawCaption(Graphics g, BitmapFont font) {
		g.setColor(0x000000);
		g.fillRoundRect(captionXPos, captionYPos, captionWidth, captionHeight, 20, 20);
		// adding padding to caption X,Y to center the text in the rounded
		// rectangle. its half of the padding added to the stringWidth and
		// stringHeight variables
		g.setColor(0xffffff);
		if (font != null)
			font.drawString(g, caption, captionXPos + 3, captionYPos + 2, 0);
		else
			g.drawString(caption, captionXPos + 3, captionYPos + 2, 0);

	}

	void drawIcon(Graphics g) {
		g.drawImage(menuImage, iconXPos, iconYPos, 0);

	}

	public String getCaption() {
		return caption;
	}

	int getCaptionHeight() {
		return captionHeight;
	}

	int getCaptionWidth() {
		return captionWidth;
	}

	int getCaptionXPos() {
		return captionXPos;
	}

	int getCaptionYPos() {
		return captionYPos;
	}

	public String getCategoryId() {
		return categoryId;
	}

	int getIconXPos() {
		return iconXPos;
	}

	int getIconYPos() {
		return iconYPos;
	}

	public String getMenuId() {
		return menuId;
	}

	public Image getMenuImage() {
		return menuImage;
	}

	public MacScreenMenu[] getSubmenu() {
		return submenu;
	}

	public MacScreenMenu getSubMenuAtIndex(int index) {
		return submenu[index];
	}

	public boolean hasSubmenu() {
		return hasSubmenu;
	}

	public boolean isReport() {
		return isReport;
	}

	public void setCaption(String caption) {

		this.caption = caption;
	}

	void setCaptionHeight(int stringHeight) {
		this.captionHeight = stringHeight;
	}

	void setCaptionWidth(int stringWidth) {
		this.captionWidth = stringWidth;
	}

	void setCaptionXPos(int captionXPos, int scrWidth) {
		this.captionXPos = (captionXPos < 0) ? 0 : captionXPos;
		int temp = (captionXPos + captionWidth) - scrWidth;
		if (temp > scrWidth) {
			this.captionXPos = this.captionXPos - temp;
		}
		if (captionXPos + captionWidth > scrWidth) {
			System.out.println("The caption cannot be accomodated in the screen");
			this.captionXPos = this.captionXPos - captionWidth - subMenuWidth;
		}
	}

	void setCaptionYPos(int captionYPos) {
		this.captionYPos = captionYPos;
	}

	public void setCategoryId(String categoryId) {
		this.categoryId = categoryId;
	}

	void setIconXPos(int pos) {
		iconXPos = pos;
	}

	void setIconYPos(int pos) {
		iconYPos = pos;
	}

	public void setMenuId(String menuId) {
		this.menuId = menuId;
	}

	public void setMenuImage(Image menuImage) {
		this.menuImage = menuImage;
	}

	public void setReport(boolean isReport) {
		this.isReport = isReport;
	}

	public void setSubmenu(MacScreenMenu[] submenu) {
		if (submenu != null) {
			this.hasSubmenu = true;
			this.submenu = submenu;
		}
	}

	void setSubMenuWidth(int subMenuWidth) {
		this.subMenuWidth = subMenuWidth;
	}

}
